FAQ: How to Get Better at Testing? (using the 12 Essentials)
How to Get Better at Testing
[00:00:00]
All right, so this one is called how to get better at testing. I love this question. Testing sucked for me. It was so hard to figure out how to do testing. The first times I ever tried to do testing, yeah, I just ended up testing stuff that didn't need to be tested like sequelized models. And I ended up writing end to end tests that were super flaky and that did not work out well for me at all.
So this topic means a lot to me. So yeah, let's, let me walk through this one here. You should already know this, we've discussed this in the metaphysics as well, but testing, design, architecture, strategy, all of these topics, these are the four pillars this is the stuff that really matters, but they're all intertwined and they're so difficult to learn because it takes a high level of mastery.
You need to build up a little bit in all of [00:01:00] them in order to do even one of them correctly, it feels that's why I've put together a roadmap based on a path that I've personally walked and I've seen some other developers walk as well. And on that path, the first thing I want you to do in the code first phase of craftship is just.
I just want you to build something out on the backend that doesn't really matter. The reason why I want you to do some work on the backend is because it's going to give us the ability to think a little bit more purely about what it is we're doing. I know a lot of developers are doing work on the frontend, and on the frontend we're dealing with frontend abstractions and tools and all this different thought leadership around how to test things and what things are.
Let's go to the backend where you have none of that and it's all raw and you have to think about. The structure of the code and the testing. In code first, I'm just going to get you to build something up basic operations on the back end. And then in best practice first, what I'm going to get you to do is to learn the basics of testing.
So this is just going to be you mastering [00:02:00] the TDD mechanics, red green refactor, that sort of thing. Keeping it nice and easy, nice and simple. I'm going to get you to start thinking backwards. to start structuring out your code by starting with the examples and using parameterization. So just some good practices and principles around testing in general.
But fundamentally, these are all input output tests, and they're really nice and easy and simple for you to write. Then, later on in best practice first, what I want you to do is to learn how to write end to end tests, but I'm going to show you how to do it in a non flaky way. So everyone here is probably trying to write end to end tests.
If you're a front end developer, you're probably trying to, but you're probably not loving it. You're probably struggling with it to a degree and maybe feeling like it's not worth it. Or maybe you just have a QA team that's doing that thing instead. End to end tests are incredible when they are designed with the appropriate levels of abstraction.
You need to have four layers of [00:03:00] abstraction. In order to do end to end testing properly. It is still input output testing. We're still just going to be testing the entirety of the system. It's not all that different. It's just the size of the system that we're testing. Where earlier I'm going to make sure that you're testing just functions.
Now I'm going to make you test the entire system as a function. So we're still going to be doing input output testing and best practice first. And I'm going to show you how to do this against the entire system. But. We'll take it up a step further where you're going to have to do some other things that are just, in reality, you also need to make sure that you can write your tests in different environments.
We'll have to pull in composition and pull in some other techniques. But where things get really interesting is in the pattern first phase because that's when we need to get into decoupling. And if you know anything about the hexagonal architecture, the clean architecture, the onion architecture, Kind of all different ways to say the same thing for the most part.
What we need to do is we [00:04:00] need to decouple core code from infrastructure code. And when we do that, we actually give ourselves a large number of testing options. So this is what's going to give us the ability to write high value unit tests. It's going to give us the ability to write high value integration tests.
It will give us the ability to stub, mock, to control the edge cases for our scenarios. to just really try out a bunch of different testing strategies and different approaches. And you're going to develop this kind of ninja like approach to decouple things from each other and then slot in your tests and isolate exactly what it is you would like to test and forget everything else.
And that is the skill. That's the foundational skill that I think everyone needs. And we're going to need to use the essential of subject or system verification. to do this, but we're going to also need to practice the other parts of subject verification, which is [00:05:00] communication or behavior verification, and also state verification.
This is a lot of different words I'm saying to you, and maybe this is confusing, especially if you've just watched the metaphysics module just once it might be worth watching it again. However, we are going to go into depth on all of this stuff. If it does seem like a lot, it is a lot. We're going to move through it strategically in piece by piece so it won't feel like a lot when we get to it.
But this is the frequently asked question is how do I get better at testing? I'm making sure I'm giving a very clear, succinct response here because this is really important. Things like integration testing, end to end testing, acceptance testing, unit testing. We could call those all different sorts of things.
But once you also learn how to use the guess points and you can start to think through the design of a system as systems thinking you can see how things, you can see how these little systems bleed into each other. Your testing is really cool because then you could say, Oh, I just want to test this system to that system and then leave maybe the system out.
I [00:06:00] don't care about the incoming up to the system level very much. I just want to be able to test from the application all the way to the end. So that's the outgoing adapter. So that itself would now be called an integration test because we're going to be testing everything from the app all the way to the database and any of the services that are being used.
Integration test. Versus if we just wanted to test the application and up to but not including the database, then we're just testing the application in the domain logic. Then that is a unit test because it's going to be pure core code. So this is some of the stuff you're going to learn how to do. So to get better at testing, you need to become the person who can isolate what it is you would like to isolate and move concerns and responsibilities around so that the concerns and responsibilities are in the correct place so that you can decouple, so that you can test.
So hopefully that made sense. [00:07:00] And once you have that ability, then what you could do is in, we'll do this in value first, we can get into deciding on testing strategies that we actually want to use. There's the ideal developer workflow, but there's different variations on that and there's different ways you could write tests that are highly valuable.
Ultimately, you just want the highest level of confidence. And to have to do the least amount of work based on where you currently are. Yeah, that is how to get better at testing. Go through the phases of craftship and you will see that you should be a lot better at testing by the time we get to the end.
